package ch.esn.server.service;

import ch.esn.client.service.UserService;
import ch.esn.server.converter.UserConverter;
import ch.esn.shared.gxt.model.UserModel;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class UserServiceImpl extends RemoteServiceServlet implements UserService {

	final static public com.google.appengine.api.users.UserService userService = UserServiceFactory.getUserService();

	public UserModel getLoggedUser() {
		User loggedUser = userService.getCurrentUser();

		return UserConverter.getInstance().getModel(loggedUser);
	}

	public String getLoginURL(String forURL) {
		try {
			return userService.createLoginURL(forURL);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

	public String getLogoutURL(String forURL) {
		return userService.createLogoutURL(forURL);
	}

	public boolean isUserLoggedIn() {
		return userService.isUserLoggedIn();
	}

}
